<template>
    <div class="e-table billList">
        <div class="top">
            <div class="left">
                <div class="listTop">
                    <el-button
                        size="small"
                        class="btn-greenYellow"
                        @click="openAddDialog"
                    >
                        新增</el-button
                    >
                </div>
            </div>
            <div class="right">
                <div class="right-div1">
                    <el-input
                        placeholder="请输入关键字"
                        size="small"
                        v-model="pagination.keyword"
                        @blur="search"
                    >
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="search"></i>
                    </el-input>
                </div>
                <div>
                    <el-button
                        size="small"
                        style="background: #2e61d7; color: #fff"
                        @click="heightSharch"
                        >高级搜索
                    </el-button>
                </div>
            </div>
        </div>
        <el-table
            class="table"
            :data="tableData"
            border
            style="width: 100%"
            highlight-current-row
        >
            <el-table-column label="盘点编号" width="300" class-name="blue-column">
                <template slot-scope="{ row }" >
                    <span @click="tableDbShow(row)">{{row.billNo}}</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="orgName"
                label="机构"
                align="center"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
              <el-table-column
                prop="year"
                label="年度"
                width="230"
            >
            </el-table-column>
            <el-table-column
                prop="state"
                label="状态"
                width="230"
            >
                <template slot-scope="{ row }">
                    <span>{{ statusLable(row.state) }}</span>
                </template>
            </el-table-column>
        </el-table>
        <ComPagination
            :total="totalPage"
            :pageSize.sync="pagination.limit"
            :currentPage.sync="pagination.page"
            @currentChange="listByEntity"
            @sizeChange="listByEntity"
            class="bottomSetting"
        />
    </div>
</template>

<script>
import request from '@/api/equip/dailyManagement.js'
import ComPagination from '@/components/pagination/pagination.vue'
import { mapState, mapMutations } from 'vuex'
import { advanceSearch } from '@/utils/common.js'
export default {
    data () {
        return {
            tableData: [],
            loading: false,
            pagination: {
                'endTime': '',
                'founderId': '',
                'keyword': '',
                'limit': 20,
                'loginOrgid': '',
                'orgId': '',
                'page': 1,
                'startTime': '',
                'states': []
            },
            totalPage: 0, //总页数
        }
    },
    components: {
        ComPagination
    },
    computed: {
        ...mapState({
            workStatus: state=>state.equip.equipData.workStatus,
            assessmentLevel: state=>state.equip.equipData.assessmentLevel,
        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
    },
    created () {
        this.getList()
    },
    mounted () {
    },
    methods: {
        ...mapMutations(['setSearchData']),
        getList () {
            request.assetsInventoryList(this.pagination).then(res=>{
                this.tableData = res.list
                this.totalPage = res.totalCount
            })
        },
        //分页查询
        listByEntity () {
            this.getList()
        },
        //普通搜索
        search () {
            this.getList()
        },
        //高级查询
        heightSharch () {
            advanceSearch('/equipPlanHeightSearch').then(res => {
                this.pagination = res.equipSearchData
                this.getList()
                this.clearData()
            })
        },
        //清空高级搜索的数据
        clearData () {
            this.pagination = {
                'endTime': '',
                'founderId': '',
                'keyword': '',
                'limit': 20,
                'loginOrgid': '',
                'orgId': '',
                'page': 1,
                'startTime': '',
                'states': []
            }
            this.setSearchData({ equipSearchData: this.pagination })
        },
        //新增
        openAddDialog () {
            this.$router.push('/assetsInventoryAdd')
        },
        //编辑
        tableDbEdit (billid) {
            this.$router.push({
                path: '/assetsInventoryEdit',
                query: { billid }
            })
        },
        //查看
        tableDbShow (row) {
            this.$router.push({
                path: '/assetsInventoryShow',
                query: { billid: row.billId }
            })
        },
    }
}
</script>

<style lang="scss" scoped>
.dialog-footer {
    text-align: right;
}
</style>
